package com.aliyun.messagemgt.application.service.Impl;


import com.aliyun.messagemgt.common.dto.send.MsgRecordVO;
import com.aliyun.messagemgt.application.service.UrlAppender;
import com.aliyun.messagemgt.util.MessageTypeUtil;
import org.springframework.stereotype.Component;

/**
 * Created with IDEA
 *
 * @author:zhangxingxing 0027012120
 * @date:2019/3/5
 * @time:13:41
 */
@Component
public class UrlAppenderImpl implements UrlAppender {

    //@Value("${h5.url.prefix}")
    private String urlPrefix;
    //@Value("${h5.common.template}")
    private String commonTemplate;
    //@Value("${h5.face.template}")
    private String faceTemplate;

    private static final Integer FACE_TYPE = 4;
    private static final String PARAM = "?msgId=";

    @Override
    public String appendUrl(MsgRecordVO msgRecordVO) {
        StringBuilder url = new StringBuilder();
        url.append(urlPrefix);
        // 根据模板选择不同的H5模板
        Integer type = MessageTypeUtil.getIntMessageType(msgRecordVO.getMessageType());
        // 拼接参数 目前只有人脸对比和普通的这两种
        if (FACE_TYPE.equals(type)) {
            url.append(faceTemplate);
        } else {
            url.append(commonTemplate);
        }
        url.append(PARAM).append(msgRecordVO.getMsgId());
        return url.toString();
    }

}
